package edu.whu.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.whu.demo.domain.Commodity_suppliers;
import edu.whu.demo.dao.Commodity_suppliersDao;
import edu.whu.demo.service.ICommodity_suppliersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yang hengyi
 * @since 2022-10-24
 */
@Service
public class Commodity_suppliersServiceImpl extends ServiceImpl<Commodity_suppliersDao, Commodity_suppliers> implements ICommodity_suppliersService {
    @Override
    public List<Long> getSupplierByCommodity(Long id) {
        QueryWrapper<Commodity_suppliers> qw = new QueryWrapper<>();
        qw.eq("commodity_id", id);
        List<Long> ids = new ArrayList<>();
        List<Commodity_suppliers> list = getBaseMapper().selectList(qw);
        for(Commodity_suppliers commodity_suppliers: list){
            ids.add(commodity_suppliers.getSuppliersId());
        }
        return ids;
    }

    public void batchDeleteByCommodityId(long id) {
        QueryWrapper<Commodity_suppliers> qw = new QueryWrapper<>();
        qw.lambda().eq(Commodity_suppliers::getCommodityId, id);
        getBaseMapper().delete(qw);
    }
}
